package com.wxtt.android.activity;

import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.fast.dev.frame.ui.Bind;
import com.fast.dev.frame.ui.ContentView;
import com.fast.dev.frame.utils.DateUtils;
import com.wxtt.android.R;
import com.wxtt.android.common.CommonActivity;
import com.wxtt.android.config.SpConfig;
import com.wxtt.android.view.HandlerHelper;

/**
 * 说明：欢迎页
 * <p/>
 * 作者：fanly
 * <p/>
 * 时间：2015/12/28 15:02
 * <p/>
 * 版本：verson 1.0
 */
@ContentView(R.layout.activity_welcome)
public class WelcomeActivity extends CommonActivity{

    @Bind(id = R.id.tv_welcome_time)
    TextView tv_welcome_time;
    @Bind(id = R.id.tv_welcome_content)
    TextView tv_welcome_content;

    private Animation animation;


    @Override
    protected void setContentViewBefor() {
        //设置全屏显示
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    @Override
    public void onInit(Bundle bundle) {
        tv_welcome_time.setText(getTime());
        tv_welcome_content.setText(getWelcomeContent());
        createAnimation();
        HandlerHelper.postDelay(1000, new Runnable() {
            @Override
            public void run() {
                bind(R.id.iv_welcome_bg).startAnimation(animation);
            }
        });
    }

    private void createAnimation(){
        animation = AnimationUtils.loadAnimation(WelcomeActivity.this, R.anim.splash);
//        AccelerateDecelerateInterpolator interpolator = new AccelerateDecelerateInterpolator();
//        animation.setInterpolator(interpolator);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                skipActivity(WelcomeActivity.this, MainActivity.class);
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    /**
     * 说明：获取时间
     * @return
     */
    private String getTime(){
        return DateUtils.getNowTime("yyyy年 M月 dd日，")+DateUtils.WEEKDAYS[DateUtils.getWeekDay()];
    }

    private String getWelcomeContent(){
        return SpConfig.getWelcomeText(getString(R.string.app_welcome_deftext));
    }
}
